package strings;

/**
 * Created by Tzachi on 08/10/2014.
 */
public class Main {

    public static void removeDuplicates(char[] input) {
        if (input == null) return;
        int len = input.length;
        if (len < 2) return;
        for (int i = 0; i < len; i++) {
            char c = input[i];
            if (c == 0) continue;
            for (int j = i + 1; j < len; j++) {
                if (c == input[j]) {
                    input[j] = 0;
                }
            }
        }
    }

    public static void rotateMatrix(int[][] matrix) {
        int matrixSize = matrix.length - 1;
    /* 	1	2	3			7	4	1
		4	5	6	----->	8	5	2
		7	8	9			9	6	3
	*/
        for (int i = 0; i <= matrixSize / 2; i++) {
            for (int j = 0; j <= matrixSize / 2; j++) {
                int tmp00 = matrix[i][j];
                int tmp01 = matrix[matrixSize - i][j];
                int tmp10 = matrix[i][matrixSize - j];
                int tmp11 = matrix[matrixSize - i][matrixSize - j];
                matrix[i][matrixSize - j] = tmp00;
                matrix[matrixSize - i][matrixSize - j] = tmp01;
                matrix[matrixSize - i][j] = tmp11;
                matrix[i][j] = tmp10;
            }
        }
    }


    public static void main(String[] args) {
        char[] input = new char[]{'a', 'a', 'b', 'b'};
        removeDuplicates(input);
        System.out.println(input);

        int[][] matrixa = new int[][]{{1, 2}, {3, 4}};
        int[][] matrixb = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        rotateMatrix(matrixb);
        printMatrix(matrixb);
    }


    public static void printMatrix(int[][] matrix) {
        for (int[] ints : matrix) {
            for (int anInt : ints) {
                System.out.print(anInt + " ");
            }
            System.out.println();
        }
    }
}
